package org.springblade.resource.config;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Slf4j
@Component
public class OssUrlSerializer extends JsonSerializer<String> {

    public static String oss = "http://dev.minio.izehui.com:9000";

    @Override
    public void serialize(String value, JsonGenerator jsonGenerator, SerializerProvider provider)
            throws IOException {
        if (StringUtil.isNotBlank(value)) {
            jsonGenerator.writeString(oss + "/" + value);
        } else {
            jsonGenerator.writeString("");
        }
    }

    @Value("${oss.domain:'http://dev.minio.izehui.com:9000'}")
    public void setOss(String oss) {
        OssUrlSerializer.oss = oss;
    }
}
